bpo-44863: In TypedDict allow inherit from Generic and preserve bases#27663
Merged
JelleZijlstra merged 40 commits intopython:mainfrom May 3, 2022
Merged
bpo-44863: In TypedDict allow inherit from Generic and preserve bases#27663JelleZijlstra merged 40 commits intopython:mainfrom
JelleZijlstra merged 40 commits intopython:mainfrom
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Copied from: https://bugs.python.org/issue44863
TypedDict PEP-589 says:
A TypedDict cannot inherit from both a TypedDict type and a non-TypedDict base class.
So the current implementation has:
if type(base) is not _TypedDictMeta: raise TypeError(...)This restricts the user from defining generic TypedDicts in the natural class based syntax:
class Pager(TypedDict, Generic[T]): ...Although PEP 589 doesn't explicitly state generic support, I believe it is complete in covering the specification even if generics were involved (at least for the class based syntax).
I have tried putting together a PEP from guidance of typing-sig https://github.com/sransara/py-generic-typeddict/blob/master/pep-9999.rst. There is not much new contributions by that draft, except for specifying the alternative syntax and being more explicit about Generics.
So I'm wondering if it would be possible to relax the constraint: TypedDict inheritance to include Generic. In my point of view
Genericis more of a mixin, so it doesn't go against the PEP 589. Or is this change big enough to warrant a PEP?https://bugs.python.org/issue44863